<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path;
%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
<title>云校通-教师-课程审批</title>
<jsp:include page="/WEB-INF/page/common/_header.jsp"></jsp:include>
</head>
<body ontouchstart style="background: #fff;">
	<div class="weui_tab tab-bottom">
		<div class="weui-header bg-blue"> 
	  		<div class="weui-header-left"><a href="<%=basePath %>/ls/interest/course?from=sys" class="icon icon-109 f-white">返回</a></div>
	    	<h1 class="weui-header-title">课程审批</h1>
		</div>
		<div class="weui_tab_bd">
	        <div class="weui_tab kcfd-list1" id="tab4">
	            <div class="weui_navbar">
	                <div class="weui_navbar_item">
	                    	待审批
	                </div>
	                <div class="weui_navbar_item" id="ccList">
	                    	已审批
	                </div>
	            </div>
	            <div class="weui_tab_bd">
	                
		            <div class="weui_panel weui_tab_bd_item qingjia mt0">
			            <div class="weui_panel_bd" id="pendingApproval">
			                
			            </div>
			            <div class="dropload-down">
						    <div class="loadData dropload-hasData">点击加载更多数据...</div>
						</div>
		            </div>
			        
		            <div class="weui_panel weui_tab_bd_item qingjia mt0">
			            <div class="weui_panel_bd" id="approved">
			                
			            </div>
			            <div class="dropload-down">
						    <div class="loadData dropload-hasData">点击加载更多数据...</div>
						</div>
		            </div>
	            </div>
	        </div>
		</div>
	</div>
	<jsp:include page="/WEB-INF/page/common/_footer.jsp"></jsp:include>
	<script>
		var isLoadccList = false;
		var myPage = 1,myRows = 15,ccPage = 1, ccRows = 15;
		$(function() {
			$('#tab4').tab({
				defaultIndex: 0,
				activeClass: "tab-blue "
			});
			$("#ccList").click(function() {
				if(!isLoadccList){
					loadccList();
				}
			})
			$(".dropload-down").on("click", ".dropload-hasData", function() {
				var id = $(this).closest(".weui_tab_bd_item").find(".weui_panel_bd").attr("id");
				var param = {
					page: id == 'pendingApproval' ? myPage : ccPage,
					rows: id == 'pendingApproval' ? myRows : ccRows
				}
				if(id == 'pendingApproval') {
					myPage+=1;
				}else {
					ccPage+=1;
				}
				loadItem(param, id);
			})
			var param = {
				page: myPage,
				rows: myRows
			}
			myPage+=1;
			loadItem(param,"pendingApproval");
		});
		function loadccList(){
			isLoadccList = true;
			var param = {
				page: ccPage,
				rows: ccRows
			}
			ccPage += 1;
			loadItem(param, "approved");
		}
		function loadItem(param, id) {
			var url = basePath + "/ls/interest/course/pending/list";
			if(id == "approved") {
				url = basePath + "/ls/interest/course/approved/list";
			}
			$.ajax({
				url: url,
				type: 'post',
				dataType: 'json',
				data: param,
				success: function(data) {
					var html = "";
					if(data.data.rows.length == 0 || param.page*param.rows >= data.data.total) {// 如果没有数据
	            		 $("#" + id).closest(".weui_tab_bd_item").find('.loadData').removeClass("dropload-hasData").addClass("dropload-noData").html("没有更多数据了");
	                }
					for(var i in data.data.rows) {
						var itm = data.data.rows[i];
						if(itm.isAgree == 0) {
							html += '<a href="<%=basePath%>/ls/interest/course/approvalDetail/'+itm.id+'" class="weui_media_box weui_media_appmsg">';
						}else {
							html += '<a href="<%=basePath%>/ls/interest/course/detail/'+itm.id+'" class="weui_media_box weui_media_appmsg">';
						}
				    	html += '<div class="weui_media_hd weui_media_hd80">';
				    	if(itm.mainImg) {
				    		html += '<img class="weui_media_appmsg_thumb weui_media_img80" src="'+imgUrl + itm.mainImg+'">';
				    	}else {
				    		html += '<img class="weui_media_appmsg_thumb weui_media_img80" src="<%=basePath%>/images/xqkt_default.png"/>';
				    	}
					    html += '</div><div class="weui_media_bd">';
				        html += '<h4 class="weui_media_title">'+itm.courseName+'</h4>';
				        html += '<p class="weui_media_desc pt5">审批状态: ';
				        if(itm.isAgree == 0) {
				        	html += '<span class="f-orange">待审核</span>';
				        }else if(itm.isAgree == 1) {
				        	html += '<span class="f-green">同意</span>';
				        }else if(itm.isAgree == 2) {
				        	html += '<span class="f-red">驳回</span>';
				        }
				        html += '</p><p class="weui_media_desc web-line-clamp3 pt5">'+itm.courseDesc+'</p>';
				        html += '</div></a>';
					}
					$("#" + id).append(html);
				}
			});
		}
	</script>
</body>
</html>